﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar
{
    public class ucDayOfWeekContentItem : Control
    {
        #region Dependency Variables
        public static readonly DependencyProperty DisplayDayProperty = DependencyProperty.Register("DisplayDay", typeof(Visibility), typeof(ucDayOfWeekContentItem), new PropertyMetadata(Visibility.Visible, new PropertyChangedCallback(DisplayDay_Changed)));
        public static readonly DependencyProperty DayProperty = DependencyProperty.Register("Day", typeof(string), typeof(ucDayOfWeekContentItem), new PropertyMetadata(DateTime.Now.Day.ToString(), new PropertyChangedCallback(Day_Changed)));
        public static readonly DependencyProperty DayStringProperty = DependencyProperty.Register("DayString", typeof(string), typeof(ucDayOfWeekContentItem), new PropertyMetadata(DateTime.Now.DayOfWeek.ToString(), new PropertyChangedCallback(DayString_Changed)));
        public static readonly DependencyProperty MonthProperty = DependencyProperty.Register("Month", typeof(string), typeof(ucDayOfWeekContentItem), new PropertyMetadata(DateTime.Now.Month.ToString(), new PropertyChangedCallback(Month_Changed)));
        public static readonly DependencyProperty MonthStringProperty = DependencyProperty.Register("MonthString", typeof(string), typeof(ucDayOfWeekContentItem), new PropertyMetadata(DateTime.Now.Month.ToString(), new PropertyChangedCallback(MonthString_Changed)));
        public static readonly DependencyProperty YearProperty = DependencyProperty.Register("Year", typeof(string), typeof(ucDayOfWeekContentItem), new PropertyMetadata(DateTime.Now.Year.ToString(), new PropertyChangedCallback(Year_Changed)));
        #endregion

        #region Dependency Properties
        public Visibility DisplayDay
        {
            get { return (Visibility)this.GetValue(DisplayDayProperty); }
            set { this.SetValue(DisplayDayProperty, value); }
        }
        public string Day
        {
            get { return this.GetValue(DayProperty).ToString(); }
            set { this.SetValue(DayProperty, value); }
        }
        public string DayString
        {
            get { return this.GetValue(DayStringProperty).ToString(); }
            set { this.SetValue(DayStringProperty, value); }
        }
        public string Month
        {
            get { return this.GetValue(MonthProperty).ToString(); }
            set { this.SetValue(MonthProperty, value); }
        }
        public string MonthString
        {
            get { return this.GetValue(MonthStringProperty).ToString(); }
            set { this.SetValue(MonthStringProperty, value); }
        }
        public string Year
        {
            get { return this.GetValue(YearProperty).ToString(); }
            set { this.SetValue(YearProperty, value); }
        }
        #endregion

        #region Dependency Events
        #region DisplayDay_Changed
        private static void DisplayDay_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnDisplayDay_Changed(e);
        }
        #endregion

        #region Day_Changed
        private static void Day_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnDay_Changed(e);
        }
        #endregion

        #region DayString_Changed
        private static void DayString_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnDayString_Changed(e);
        }
        #endregion

        #region Month_Changed
        private static void Month_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnMonth_Changed(e);
        }
        #endregion

        #region MonthString_Changed
        private static void MonthString_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnMonthString_Changed(e);
        }
        #endregion

        #region Year_Changed
        private static void Year_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayOfWeekContentItem).OnYear_Changed(e);
        }
        #endregion
        #endregion

        #region Variables
        private Border brdRoot = null;
        #endregion

        #region Properties
        public DateTime Date
        {
            get { return new DateTime(Int32.Parse(Year), Int32.Parse(Month), Int32.Parse(Day)); }
        }
        #endregion

        #region Event Variables
        public event EventHandler DayOfWeek_Selected;
        #endregion

        #region Constructor
        public ucDayOfWeekContentItem()
        {
            DefaultStyleKey = typeof(ucDayOfWeekContentItem);
        }
        #endregion

        #region Methods
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            brdRoot = (Border)base.GetTemplateChild("brdRoot");

            if (brdRoot == null) return;

            brdRoot.MouseLeftButtonUp += new MouseButtonEventHandler(brdRoot_MouseLeftButtonUp);
        }
        #endregion

        #region OnDisplayDay_Changed
        protected virtual void OnDisplayDay_Changed(DependencyPropertyChangedEventArgs e)
        {
            DisplayDay = (Visibility)e.NewValue;
        }
        #endregion

        #region OnDay_Changed
        protected virtual void OnDay_Changed(DependencyPropertyChangedEventArgs e)
        {
            Day = e.NewValue.ToString();
        }
        #endregion

        #region OnDayString_Changed
        protected virtual void OnDayString_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayString = e.NewValue.ToString();
        }
        #endregion

        #region OnMonth_Changed
        protected virtual void OnMonth_Changed(DependencyPropertyChangedEventArgs e)
        {
            Month = e.NewValue.ToString();
        }
        #endregion

        #region OnMonthString_Changed
        protected virtual void OnMonthString_Changed(DependencyPropertyChangedEventArgs e)
        {
            MonthString = e.NewValue.ToString();
        }
        #endregion

        #region OnYear_Changed
        protected virtual void OnYear_Changed(DependencyPropertyChangedEventArgs e)
        {
            Year = e.NewValue.ToString();
        }
        #endregion
        #endregion

        #region Events
        #region brdRoot_MouseLeftButtonUp
        private void brdRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Border brd = (Border)sender;

            if (DayOfWeek_Selected != null)
                DayOfWeek_Selected(this, null);
        }
        #endregion
        #endregion
    }
}
